package com.iflyteck.service.impl;

import com.github.pagehelper.PageHelper;
import com.iflyteck.mapper.ArticleMapper;
import com.iflyteck.pojo.Article;
import com.iflyteck.repository.ArticleRepository;
import com.iflyteck.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleRepository articleRepository;

    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public List<Article> queryArticlePage(Integer page, Integer size) {
        PageRequest pa = PageRequest.of(page, size);
        Page<Article> all = articleRepository.findAll(pa);
        List<Article> articles = all.getContent();
        return articles;
    }

    // 使用mybatis查询
    @Override
    public List<Article> queryArticle(Integer page, Integer size) {
        PageHelper.startPage(page,size);
        List<Article> all = articleMapper.queryArticle();
        return all;
    }


}
